package util

import (
	"time"
)

const (
	BaiYang1 = iota + 1
	BaiYang2
	BaiYang3
	JinNiu1
	JinNiu2
	JinNiu3
	ShuangZi1
	ShuangZi2
	ShuangZi3
	JuXie1
	JuXie2
	JuXie3
	ShiZi1
	ShiZi2
	ShiZi3
	ChuNv1
	ChuNv2
	ChuNv3
	TianPing1
	TianPing2
	TianPing3
	TianXie1
	TianXie2
	TianXie3
	Sheshou1
	Sheshou2
	Sheshou3
	MoJie1
	MoJie2
	MoJie3
	ShuiPing1
	ShuiPing2
	ShuiPing3
	ShuangYu1
	ShuangYu2
	ShuangYu3
)

func GetResult(date int64) int {
	birthday, _ := time.Parse("20060102", time.Unix(int64(date), 0).Format("20060102"))
	day := birthday.Day()
	month := birthday.Month()
	switch GetConstellation(birthday) {
	//选择每一种星座的每种结果
	case "BaiYang":
		{
			if day <= 30 && day >= 21 {
				return BaiYang1
			}
			if day <= 9 && day >= 1 || day == 31 {
				return BaiYang2
			}
			if day <= 20 && day >= 10 {
				return BaiYang3
			}
		}
	case "JinNiu":
		{
			if day <= 29 && day > 20 || month == 4 && day == 20 {
				return JinNiu1
			}
			if day <= 10 && day >= 1 || day == 30 || day == 31 {
				return JinNiu2
			}
			if day < 20 && day >= 11 || month == 5 && day == 20 {
				return JinNiu3
			}
		}
	case "ShuangZi":
		{
			if day <= 30 && day > 21 || month == 5 && day == 21 {
				return ShuangZi1
			}
			if day <= 9 && day >= 1 || day == 31 {
				return ShuangZi2
			}
			if day < 21 && day >= 10 || month == 6 && day == 21 {
				return ShuangZi3
			}
		}
	case "JuXie":
		{
			if day <= 30 && day > 22 || day == 1 || month == 6 && day == 22 {
				return JuXie1
			}
			if day <= 11 && day >= 2 {
				return JuXie2
			}
			if day < 22 && day >= 12 || month == 7 && day == 22 {
				return JuXie3
			}
		}
	case "ShiZi":
		{
			if day <= 31 && day >= 23 || day == 1 || day == 2 {
				return ShiZi1
			}
			if day <= 12 && day >= 3 {
				return ShiZi2
			}
			if day <= 22 && day >= 13 {
				return ShiZi3
			}
		}
	case "ChuNv":
		{
			if day <= 31 && day >= 23 || day == 1 || day == 2 {
				return ChuNv1
			}
			if day <= 12 && day >= 3 {
				return ChuNv2
			}
			if day <= 22 && day >= 13 {
				return ChuNv3
			}
		}
	case "TianPing":
		{
			if day <= 30 && day > 23 || day == 1 || day == 2 || month == 9 && day == 23 {
				return TianPing1
			}
			if day <= 12 && day >= 3 {
				return TianPing2
			}
			if day < 23 && day >= 13 || month == 10 && day == 23 {
				return TianPing3
			}
		}
	case "TianXie":
		{
			if day <= 31 && day >= 24 || day == 1 || day == 2 || day == 3 {
				return TianXie1
			}
			if day <= 13 && day >= 4 {
				return TianXie2
			}
			if day <= 22 && day >= 14 {
				return TianXie3
			}
		}
	case "SheShou":
		{
			if day <= 30 && day >= 22 || day == 1 || day == 2 {
				return Sheshou1
			}
			if day <= 12 && day >= 3 {
				return Sheshou2
			}
			if day <= 21 && day >= 13 {
				return Sheshou3
			}
		}
	case "MoJie":
		{
			if day <= 31 && day >= 22 || day == 1 {
				return MoJie1
			}
			if day <= 11 && day >= 2 {
				return MoJie2
			}
			if day <= 19 && day >= 12 {
				return MoJie3
			}
		}
	case "ShuiPing":
		{
			if day <= 30 && day >= 20 {
				return ShuiPing1
			}
			if day <= 9 && day >= 1 || day == 31 {
				return ShuiPing2
			}
			if day <= 18 && day >= 10 {
				return ShuiPing3
			}
		}
	case "ShuangYu":
		{
			if day <= 29 && day >= 19 && month == 2 {
				return ShuangYu1
			}
			if day <= 10 && day >= 1 {
				return ShuangYu2
			}
			if day <= 20 && day >= 11 && month == 3 {
				return ShuangYu3
			}
		}
	}
	return 0
}

//GetConstellation 获取星座
func GetConstellation(d time.Time) string {
	Month := d.Month()
	Month = Month - 1
	Day := d.Day()
	var (
		DAY_ARR       = [12]int{20, 19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22}
		Constellation = [13]string{"MoJie", "ShuiPing", "ShuangYu", "BaiYang", "JinNiu", "ShuangZi", "JuXie", "ShiZi", "ChuNv", "TianPing", "TianXie", "SheShou", "MoJie"}
	)
	if Day < DAY_ARR[Month] {
		return Constellation[Month]
	} else {
		return Constellation[Month+1]
	}
}
func GetConstellations(t int64) string {
	d := time.Unix(t, 0)
	Month := d.Month()
	Month = Month - 1
	Day := d.Day()
	var (
		DAY_ARR       = [12]int{20, 19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22}
		Constellation = [13]string{"摩羯座", "水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "摩羯座"}
	)
	if Day < DAY_ARR[Month] {
		return Constellation[Month]
	} else {
		return Constellation[Month+1]
	}
}

type Info struct {
	Birthday      int64  `json:"birthday"`      // 生日
	Constellation string `json:"constellation"` // 星座
	Gender        string `json:"gender"`        //性别
	Num           int    `json:"num"`           // 编号
}

func GetInfo(gender string, birthday int64) Info {
	return Info{
		Birthday:      birthday,
		Constellation: GetConstellations(birthday),
		Gender:        gender,
		Num:           GetResult(birthday),
	}
}
